<template>
    <div class="sidebar">
      <el-menu
        class="sidebar-el-menu"
        :default-active="onRoutes"
        :collapse="collapse"
        background-color="#334256"
        text-color="#ffffff"
        active-text-color="#20a0ff"
        router
      >
        <template v-for="item in items">
          <template>
            <el-menu-item :index="item.index" :key="item.index">
              <i :class="item.icon"></i>
              {{ item.title }}
            </el-menu-item>
          </template>
        </template>
      </el-menu>
    </div>
  </template>
  
  <script>
  import bus from "../utils/bus";
  import { Icon } from "element-ui";
  export default {
    data() {
      return {
        collapse: false,
        items: [
          {
            icon: "el-icon-document",
            index: "/manage/maglifesharing",
            title: "生活分享",
          },
          {
            icon: "el-icon-reading",
            index: "/manage/maglearningexchange",
            title: "学习交流",
          },
          {
            icon: "el-icon-chat-dot-round",
            index: "/manage/magcomment",
            title: "评论管理",
          },
          {
            icon: "el-icon-s-custom",
            index: "/manage/maguser",
            title: "用户管理",
          },
          {
            icon: "el-icon-collection-tag",
            index: "/manage/magpostsection",
            title: "分区管理",
          },
          {
            icon: "el-icon-s-comment",
            index: "/manage/magsuggestion",
            title: "建设建议管理",
          },
          
          
        ],
      };
    },
    computed: {
      onRoutes() {
        //返回当前路由地址
        // return this.$route.path.replace("/", "");
        console.log(this.$route.path)
        return this.$route.path;
      },
    },
    mounted() {
      console.log(this.$route.path);
      console.log("我是菜单页");
    },
    created() {
      bus.$on("collapseChange", (msg) => {
        this.collapse = msg;
      });
    },
  };
  </script>
  
  <style scoped>
  .sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    background-color: #334256;
    overflow-y: scroll;
  }
  /* 将侧边栏的白边设置为零 */
  .sidebar::-webkit-scrollbar {
    width: 0;
  }
  .sidebar-el-menu:not(.el-menu--collapse) {
    width: 150px;
  }
  
  .sidebar > ul {
    height: 100%;
  }
  </style>
  
  